import java.util.TreeMap;

public class Ranker extends TreeMap<Integer, String> {
	int size;
	boolean lowest;
	public Ranker(int size, boolean lowest) {
		this.size = size;
		this.lowest = lowest;
	}

	public String put(int key, String value) {
		if (size() >= size) {
			if (lowest) {
				if (firstKey() >= key)
					return null;
				remove(firstKey());
			}
			else {
				if (lastKey() <= key)
					return null;
				remove(lastKey());
			}
		}
		return super.put(key, value);
	}
};
			
